package lmycc.test.demo.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import lmycc.test.demo.domain.Menu;
import lmycc.test.demo.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.transaction.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Transactional
public class MenuController {

    ObjectMapper mapper = new ObjectMapper();
    Object entiy = null;
    @Autowired
    private MenuService menuService;
    private Map mMessage = new HashMap();

    @ResponseBody
    @RequestMapping("/getMenuList")
    public List<Menu> getMenuList() {
        List<Menu> getMenuList = menuService.findAll();
        return getMenuList;
    }

    @ResponseBody
    @RequestMapping("/addMenu")
    public Map insertMenu(@RequestBody Menu menu) {
        menuService.insertMenu(menu);
        mMessage.put("message", "success");
        return mMessage;
    }
}
